🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / map / src / commonMain / kotlin / org / meshtastic / feature / map / layers / MapLayerUri.kt
Displaying Raw • Download
feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/layers/MapLayerUri.kt renovate/fastlane-2.x-lockfile (056eed64) Text, 3.75 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.map.layers
Tff7b72import T7ee787io.ktor.http.decodeURLPart
Tff7b72import T7ee787io.ktor.http.encodeURLPath
Tff7b72import T7ee787okio.Path
Tff7b72import T7ee787okio.Path.Companion.toPath
T8b949e/**
* The characters Android's `Uri.fromFile` leaves unescaped in a path: `Uri.encode` treats alphanumerics and `_-!.~'()*`
* as safe, and the path encoder adds `/`.
*/
Tff7b72private Tff7b72const Tff7b72val Te6edf3ANDROID_PATH_SAFE Tff7b72= Ta5d6ff"Ta5d6ff_-!.~'()*/Ta5d6ff"
T8b949e/** `%` plus the two hex digits behind it. */
Tff7b72private Tff7b72const Tff7b72val Te6edf3ESCAPE_LENGTH Tff7b72= T79c0ff3
T8b949e/** Two hex digits, zero-padded, as a percent escape carries. */
Tff7b72private Tff7b72const Tff7b72val Te6edf3HEX_DIGITS Tff7b72= T79c0ff2
T8b949e/** Hexadecimal. */
Tff7b72private Tff7b72const Tff7b72val Te6edf3HEX_RADIX Tff7b72= T79c0ff1T79c0ff6
T8b949e/**
* The `file://` URI for [this], byte-identical to what Android's `Uri.fromFile` writes.
*
* Identical on purpose rather than merely valid: a layer's URI string is the key its hidden/shown state persists under,
* so an installation upgrading onto this common store has to produce the same key for the same file, or every layer the
* user had hidden comes back visible.
*
* Ktor's encoder does the work — it is the URL type this module already depends on, and it handles the UTF-8 and
* non-ASCII cases correctly. It is not quite Android's set, though: Ktor keeps the RFC 3986 sub-delimiters that are
* legal in a path — comma, ampersand, plus and friends — and Android escapes them. So its output is walked once more
* and those are escaped too, which is a much smaller thing to get right than the whole encoding.
*/
Tff7b72internal Tff7b72fun Te6edf3PathTb4b4b4.Td2a8fftoFileUriTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Ta5d6fffile://Ta5d6ff" Tff7b72+ Te6edf3toStringTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3encodeURLPathTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3escapeSubDelimitersTb4b4b4(Tb4b4b4)
T8b949e/**
* The local path behind a `file://` URI (or a bare path, which is what a hand-made item may carry). Public because the
* renderer's conversion cache also stores its files under `file://` URIs and reads them back through this.
*/
Tff7b72fun Te6edf3StringTb4b4b4.Td2a8fftoLocalPathTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3Path Tff7b72= Te6edf3removePrefixTb4b4b4(Ta5d6ff"Ta5d6fffile://Ta5d6ff"Tb4b4b4)Tb4b4b4.Te6edf3decodeURLPartTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3toPathTb4b4b4(Tb4b4b4)
T8b949e/**
* Escape what Ktor left and Android would not have.
*
* Ktor has already escaped every non-ASCII byte, so anything still unescaped here is a single ASCII character and can
* be tested directly. Existing `%XX` escapes are copied through untouched — re-escaping their `%` would double-encode
* the path.
*/
Tff7b72private Tff7b72fun Te6edf3StringTb4b4b4.Td2a8ffescapeSubDelimitersTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Te6edf3buildString Tb4b4b4{
Tff7b72var Te6edf3index Tff7b72= T79c0ff0
Tff7b72while Tb4b4b4(Te6edf3index Tff7b72< Tff7b72thisTf0883e@escapeSubDelimiters.lengthTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3char Tff7b72= Tff7b72thisTf0883e@escapeSubDelimitersTff7b72[Te6edf3indexTff7b72]
Tff7b72when Tb4b4b4{
Te6edf3char Tff7b72=Tff7b72= Ta5d6ff'%' Tff7b72&Tff7b72& Te6edf3index Tff7b72+ Te6edf3ESCAPE_LENGTH Tff7b72<Tff7b72= Tff7b72thisTf0883e@escapeSubDelimiters.length Tff7b72-Tff7b72> Tb4b4b4{
Te6edf3appendTb4b4b4(Tff7b72thisTf0883e@escapeSubDelimitersTb4b4b4, Te6edf3indexTb4b4b4, Te6edf3index Tff7b72+ Te6edf3ESCAPE_LENGTHTb4b4b4)
Te6edf3index Tff7b72+Tff7b72= Te6edf3ESCAPE_LENGTH
Tb4b4b4}
Te6edf3charTb4b4b4.Te6edf3isSafeInAndroidPathTb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tb4b4b4{
Te6edf3appendTb4b4b4(Te6edf3charTb4b4b4)
Te6edf3indexTff7b72+Tff7b72+
Tb4b4b4}
Tff7b72else Tff7b72-Tff7b72> Tb4b4b4{
Te6edf3appendTb4b4b4(Ta5d6ff'%'Tb4b4b4)Tb4b4b4.Te6edf3appendTb4b4b4(Te6edf3charTb4b4b4.Te6edf3codeTb4b4b4.Te6edf3toStringTb4b4b4(Te6edf3HEX_RADIXTb4b4b4)Tb4b4b4.Te6edf3uppercaseTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3padStartTb4b4b4(Te6edf3HEX_DIGITSTb4b4b4, Ta5d6ff'0'Tb4b4b4)Tb4b4b4)
Te6edf3indexTff7b72+Tff7b72+
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tff7b72private Tff7b72fun Te6edf3CharTb4b4b4.Td2a8ffisSafeInAndroidPathTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72=
Tff7b72this Tff7b72in Ta5d6ff'a'Tb4b4b4.Tb4b4b4.Ta5d6ff'z' Tff7b72|Tff7b72| Tff7b72this Tff7b72in Ta5d6ff'A'Tb4b4b4.Tb4b4b4.Ta5d6ff'Z' Tff7b72|Tff7b72| Tff7b72this Tff7b72in Ta5d6ff'0'Tb4b4b4.Tb4b4b4.Ta5d6ff'9' Tff7b72|Tff7b72| Tff7b72this Tff7b72in Te6edf3ANDROID_PATH_SAFE
Served by rngit 1.5.2 - Generated in 0.11s